<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>潍医附院管理平台——定时任务</title>
        <link rel="stylesheet" th:href="@{css/index.css}">
        <script type="text/javascript" th:src="@{jquery/jquery-1.12.4.min.js}"></script>
        <link th:href="@{bootstrap-3.3.7-dist/css/bootstrap.min.css}" rel="stylesheet">
    </head>
    <body>
        <div class="container">
            <table class="table table-striped table-bordered table-hover" id="tableL01">
                <caption>潍医附院管理平台——定时任务</caption>
                <tbody>
                    <tr>
                        <th>任务名称</th>
                        <th>任务方法</th>
                        <th>方法参数</th>
                        <th>cron执行表达式</th>
                        <th>计划策略</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    <tr th:each="job,iterStat : ${jobList}" th:class="${iterStat.odd}? 'odd'">
                        <td style="text-align: center;" th:text="${job.jobName}"></td>
                        <td style="text-align: center;" th:text="${job.methodName}"></td>
                        <td th:text="${job.methodParams}"></td>
                        <td style="text-align: center;" th:text="${job.cronExpression}"></td>
                        <td style="text-align: center;" th:text="${job.misfirePolicy eq '0'?'默认':(job.misfirePolicy eq '1'?'立即执行':(job.misfirePolicy eq '2'?'执行一次':'放弃执行'))}"></td>
                        <td style="text-align: center;" th:class="${job.status eq '0'?'green':'red'}" th:text="${job.status eq '0'?'正常':'暂停'}"></td>
                        <td style="text-align: center;">
                            <button type="button" th:status="${job.status}"  th:name="${job.jobId}" style="padding: 3px 12px;" th:class="${job.status eq '0'?'btn lsnrBtn btn-danger':'btn lsnrBtn btn-primary'}" th:text="${job.status eq '0'?'暂停':'启用'}"></button>&nbsp;&nbsp;
                            <button type="button" th:name="${job.jobId}" style="padding: 3px 12px;" class="btn runBtn btn-primary">立即运行一次</button>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>

        <script th:inline="javascript" type="text/javascript">
            $.ajaxSetup({
                contentType: "application/json; charset=utf-8"
            });
            var ctxPath = [[${#request.getContextPath()}]];
            $(function () {
                $(".lsnrBtn").click(function (){
                    var th = this;
                    $.post(ctxPath + "/sysjob/changeStatus", JSON.stringify({"jobId" : $(th).attr("name"), "status": ($(th).attr("status") == '0'?'1':'0')}), function (ret) {
                        if(ret.code = "0") {
                            alert(ret.msg);
                            location.reload();
                        }
                    });
                });

                $(".runBtn").click(function (){
                    var th = this;
                    $.post(ctxPath + "/sysjob/run/" + $(th).attr("name"), JSON.stringify({}), function (ret) {
                        if(ret.code = "0") {
                            alert("任务执行成功");
                        } else {
                            alert("任务执行失败");
                        }
                        location.reload();
                    });
                });
            });
        </script>
        <style>
            .red {
                color: red;
            }
            .green {
                color: green;
            }
        </style>
    </body>
</html>